#include<pthread.h>
#include<semaphore.h>
#include<stdio.h>
//#include<functional>
#include<vector>
#include<string>
#include<iostream>

class H2O {
public:
    H2O() {
        pthread_cond_init(&hc_,nullptr);
        pthread_cond_init(&oc_,nullptr);
        sem_init(&h_,0,2);
        sem_init(&o_,0,1);
        pthread_mutex_init(&mutex,nullptr);
    }

    void hydrogen() {
        sem_wait(&h_);
        // releaseHydrogen() outputs "H". Do not change or remove this line.
        releaseHxygen();
        pthread_mutex_lock(&mutex);
        count++;
        if(count==2)
        {
            pthread_cond_signal(&oc_);
            count=0;
        }
        pthread_mutex_unlock(&mutex);
        pthread_cond_wait(&hc_,&mutex);
        sem_post(&h_);
    }

    void oxygen() 
    {
        sem_wait(&o_);
        // releaseOxygen() outputs "O". Do not change or remove this line.
        pthread_cond_wait(&oc_,&mutex);
        releaseOxygen();
        pthread_cond_broadcast(&hc_);
        sem_post(&o_);
    }

    void releaseHxygen()
    {
        printf("H\n");
    }

    void releaseOxygen()
    {
        printf("O\n");
    }

private:
    pthread_cond_t hc_;
    pthread_cond_t oc_;
    sem_t h_;
    sem_t o_;
    pthread_mutex_t mutex;
    int count=0;
};

void releaseHxygen()
{
    printf("H");
}

void releaseOxygen()
{
    printf("O");
}

void* oxygen(void* args)
{
    H2O* ho=static_cast<H2O*> (args);
    //function<void()> rO=releaseOxygen;
    ho->oxygen();

    return nullptr;
}

void* hxygen(void* args)
{
    H2O* ho=static_cast<H2O*> (args);
    //function<void()> rH=releaseHxygen;
    ho->oxygen();

    return nullptr;
}

int main()
{
    std::string s;
    std::cin>>s;
    H2O* ho=new H2O();
    std::vector<pthread_t> tids;
    for(int i;i<s.size();i++)
    {
        pthread_t tid;
        if(s[i]=='H')
        {
            pthread_create(&tid,nullptr,hxygen,ho);
        }
        else if(s[i]=='O')
        {
            pthread_create(&tid,nullptr,oxygen,ho);
        }
        tids.push_back(tid);
    }

    for(auto &e:tids)
    {
        pthread_join(e,nullptr);
    }

    return 0;
}